package com.expressao;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import br.database.Botao;

import com.example.mobilefala.R;

public class AdaptadorExpressao extends BaseAdapter{
    private final Context context;
    private final ArrayList<Botao> smiles;
   // Resources resc = getContext().getResources();

   
    
    public AdaptadorExpressao(Context context, ArrayList<Botao> values) {
    //	super(context, 0);
		this.context = context;
		smiles = values;
	}

    @Override
    public Botao getItem(int position) {
        return smiles.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
//    public View getView(int position, View convertView, ViewGroup parent) {
//    	if(smiles != null){
//			Botao expressao = smiles.get(position);
//		//	vi=arg1;
//			LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//			View v = inflater.inflate(com.example.mobilefala.R.layout.expressao_detalhes, null);
//
//			ImageView img = (ImageView) v.findViewById(com.example.mobilefala.R.id.img);
//			TextView t = (TextView) v.findViewById(com.example.mobilefala.R.id.Textimg);
//		//	arg2.getFocusables(0);
//			try {
//				File f2=new File(expressao.getName_arquivo());
//
//			 	Bitmap mImageBitmap = BitmapFactory.decodeResource(img.getResources(), R.drawable.sem_img);
//			 	Bitmap iB2 = Bitmap.createScaledBitmap(mImageBitmap,150, 150, true);
//			 	img.setImageBitmap(iB2);
//			 	t.setText(expressao.getName()); 
//			 	
//			 	if(!f2.equals(null)){
//
//			 	File f = new File(expressao.getName_arquivo() + ".jpg");
//			 	Bitmap b = BitmapFactory.decodeStream(new FileInputStream(f));
//			 	Bitmap iB = Bitmap.createScaledBitmap(b,150, 150, true);
//			 	img.setImageBitmap(iB);
//			 	t.setText(expressao.getName()); 
//			 	}
//		//		Log.i("hkjhkl", "get Imagem bt null infalndo getView: " + "..//.." + arg2);
//
//			// 	Tts.view2 = arg2;
//			   } 
//				
//			    catch (FileNotFoundException e) 
//			    {
//			        e.printStackTrace();
//			    }
//			return v;
//		}
//		//return arg2;
//		return parent; 
//    }
    
    
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		Botao expressao = smiles.get(position);
		Log.i("hkjhkl", "nome do botao: " + "..//.." + expressao.getName());
        View rowView = inflater.inflate(com.example.mobilefala.R.layout.expressao_detalhes, null);
        ImageView img = (ImageView) rowView.findViewById(com.example.mobilefala.R.id.img);
		TextView t = (TextView) rowView.findViewById(com.example.mobilefala.R.id.Textimg);
		try {
			File f2=new File(expressao.getName_arquivo());

		 	Bitmap mImageBitmap = BitmapFactory.decodeResource(img.getResources(), R.drawable.sem_img);
		 	Bitmap iB2 = Bitmap.createScaledBitmap(mImageBitmap,150, 150, true);
		 	img.setImageBitmap(iB2);
		 	t.setText(expressao.getName()); 
		 	
		 	if(!f2.equals(null)){

		 	File f = new File(expressao.getName_arquivo() + ".jpg");
		 	Bitmap b = BitmapFactory.decodeStream(new FileInputStream(f));
		 	Bitmap iB = Bitmap.createScaledBitmap(b,150, 150, true);
		 	img.setImageBitmap(iB);
		 	t.setText(expressao.getName()); 
		 	}
	

		// 	Tts.view2 = arg2;
		   } 
			
		    catch (FileNotFoundException e) 
		    {
		        e.printStackTrace();
		    }

        return rowView;
    }

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return 0;
	}


}